import { LOGIN1 } from './mutations-type'
export default {
    state: {

        //   登录状态
        loginstatus: false,
        token: null,
        // 用户信息
        userInfo: {

        }
    },
    getters: {

    },
    mutations: {
        [LOGIN1]() {
            console.log(111);
        },
        // 设置
        loginSetInofo(state, user) {
            state.loginstatus = true,
                state.token = user.token,
                state.userInfo = user

            // 持久化存储
            localStorage.setItem('userInfo', JSON.stringify(user))
        },
        // 读取
        initUser(state) {
            let userInfo = JSON.parse(localStorage.getItem('userInfo'))
            if(userInfo){
                state.loginstatus = true,
                state.token = userInfo.token,
                state.userInfo = userInfo

            }
         
            
        },
        // 退出登录
        outLogin(state){
            state.loginstatus = false,
                state.token = null,
                state.userInfo = {}
                localStorage.removeItem('userInfo')
        }


    },
    actions: {

    }
}